﻿Imports System.Xml
Imports Mysoft.Map.Data

Partial Public Class WF_ProcessCommonM_Save
    Inherits System.Web.UI.Page

    Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
        Dim dataXml As String = getPostStr()
        Dim XmlDoc As New XmlDocument
        Dim nodes As XmlNodeList
        Dim i As Integer
        Dim UserGUID As String = Session("userGUID")
        Dim ProcessGUID As String = ""
        Dim orderID As Integer

        XmlDoc.LoadXml(dataXml)
        nodes = XmlDoc.SelectNodes("//row")

        Dim sqlAdd As String = ""
        Dim sqlDel As String = ""
        Dim sqlRej As String = ""

        For i = 0 To nodes.Count - 1
            ProcessGUID = nodes(i).Attributes("ProcessGUID").Value.ToString()
            If nodes(i).Attributes("ishave").Value.ToString() = "1" Then
                orderID = CInt(nodes(i).Attributes("orderID").Value.ToString())
                sqlDel = sqlDel & "DELETE FROM myWorkflowCommonModule WHERE UserGUID='" & UserGUID & "' AND ProcessGUID='" & ProcessGUID & "'"
                sqlAdd = sqlAdd & "INSERT INTO myWorkflowCommonModule(DataGUID,UserGUID,ProcessGUID,OrderID)VALUES(newid(),'" & UserGUID & "','" & ProcessGUID & "'," & orderID & ")"
            Else
                sqlRej = sqlRej & "DELETE FROM myWorkflowCommonModule WHERE UserGUID='" & UserGUID & "' AND ProcessGUID='" & ProcessGUID & "';"
            End If
        Next
        If sqlDel = "" Or sqlAdd = "" Then
            If MyDB.ExecSQL(sqlRej) >= 0 Then
                Response.Write("success")
            Else
                Response.Write("failure")
            End If
        Else
            If MyDB.ExecSQL(sqlDel) >= 0 And MyDB.ExecSQL(sqlAdd) >= 0 Then
                If MyDB.ExecSQL(sqlRej) >= 0 Then
                    Response.Write("success")
                Else
                    Response.Write("failure")
                End If
            End If
        End If
    End Sub
    Function getPostStr() As String

        Dim b(Request.InputStream.Length - 1) As Byte
        Request.InputStream.Read(b, 0, Request.InputStream.Length)

        Return System.Text.Encoding.UTF8.GetString(b)

    End Function
End Class